package cn.gowss.vnc.interceptor;

import java.io.Serializable;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.util.StringUtils;
import org.springframework.web.servlet.HandlerInterceptor;

public class AdminInterceptor implements HandlerInterceptor {

	private final Logger logger = LoggerFactory.getLogger(AdminInterceptor.class);


	/**
     * 在请求处理之前进行调用（Controller方法调用之前）
     */
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) {
    	String token = request.getHeader("token");
    	if(StringUtils.isEmpty(token)){
			token = request.getParameter("token");
    	}
    	String container = request.getParameter("container");
		String host = request.getHeader("Host");
    	logger.info("container : " + container);
    	logger.info("token : " + token);
    	logger.info("host : " + host);
    	if(!StringUtils.isEmpty(container) && !StringUtils.isEmpty(token)
			&& !StringUtils.isEmpty(host)) {
    		return true;
    	}
        return false;//如果设置为false时，被请求时，拦截器执行到此处将不会继续操作
                      //如果设置为true时，请求将会继续执行后面的操作
    }
}
